package com.fm.controller;

import com.fm.entity.User;
import com.fm.service.UserService;
import com.fm.utils.R;
import com.fm.utils.SessionUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/7/31 0031.
 */
@RestController
@RequestMapping("/api/user")
public class UserController extends MBaseController<User, UserService>{
    @Override
    public User beforeList(Map t) {
        return new User();
    }


    @Override
    public void beforeInsert(User user, HttpServletRequest request) {
        user.setAvatar("https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png");
        user.setStatus(1);
        super.beforeInsert(user, request);
    }

    @RequestMapping("/currentUser")
    @ResponseBody
    public Map getCurrentUser() {
        User user = SessionUtil.getLoginUser();
        Map reMap = new HashMap();
        reMap.put("name", user.getNickName());
        reMap.put("avatar", user.getAvatar());
        reMap.put("userid", user.getId());
        reMap.put("notifyCount",0);
        return reMap;
    }
}
